package com.example.crawler.lianjia.util;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Locale;

public class TimeUtil {

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.CHINA);
    private static final ZoneOffset chineZoneOffset = ZoneOffset.of("+8");


    public static Long getTimestamp(String time) {
        return LocalDateTime.parse(time, formatter).toInstant(chineZoneOffset).toEpochMilli();
    }

    //获取当天开始时
    public static Long getFirstTimeByToday() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTimeInMillis();
    }
}
